<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!-- base href="http://172.100.0.20/" -->
    
    <title>分配资源使用情况</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="/ncrm/Public/Admin/js/jquery-1.js"></script>
	<script type="text/javascript" src="/ncrm/Public/Admin/js/jquery-1_002.js"></script>
	<link rel="stylesheet" type="text/css" href="/ncrm/Public/Admin/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="/ncrm/Public/Admin/css/bootstrap-responsive.css">
    <link rel="stylesheet" type="text/css" href="/ncrm/Public/Admin/css/style.css">

  <script src="/ncrm/Public/Admin/js/b5m.js" charset="utf-8" id="b5mmain" type="text/javascript"></script><link type="text/css" href="/ncrm/Public/Admin/css/b5m-plugin.css" rel="stylesheet">
  <link type="text/css" href="/ncrm/Public/Admin/css/b5m.css" rel="stylesheet">
<style type="text/css">
        body {
            padding-bottom: 40px;
            font-size: 16px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
        #bg{width:100%;height:100%;top:0px;left:0px;position:absolute;filter: Alpha(opacity=50);opacity:0; background:#000000; display:none;}
       #popbox{position:absolute;width:200px; height:200px; left:55%; top:60%; margin:-200px 0 0 -200px; display:none;}

    </style>
  </head>

  <body>
    <input id="static0" value="<?php echo ($resource["resCount"]["0"]); ?>" type="hidden">
  	<input id="static1" value="<?php echo ($resource["resCount"]["1"]); ?>" type="hidden">
  	<input id="static2" value="<?php echo ($resource["resCount"]["2"]); ?>" type="hidden">
  	<input id="static3" value="<?php echo ($resource["resCount"]["3"]); ?>" type="hidden">
  	<input id="static4" value="<?php echo ($resource["resCount"]["4"]); ?>" type="hidden">
  	<input id="static5" value="<?php echo ($resource["resCount"]["5"]); ?>" type="hidden">
  	
  	<table class="table table-bordered table-hover definewidth m10">
     <tbody>
  	  <tr>
  		<td colspan="5">
  		可分配<span style="color:red"><?php echo ($zcount); ?></span>条资源:
  		</td>
  		</tr>
  		<tr>
  		<td>未使用:<span style="color:red"><?php echo ($resource["resCount"]["0"]); ?>条</span></td>
  		<td>申请未通过:<span style="color:red"><?php echo ($resource["resCount"]["1"]); ?>条</span></td>
  		<td>已通过:<span style="color:red"><?php echo ($resource["resCount"]["2"]); ?>条</span></td>
  		<td>意向客户:<span style="color:red"><?php echo ($resource["resCount"]["3"]); ?>条</span></td>
  		<td>已入金:<span style="color:red"><?php echo ($resource["resCount"]["4"]); ?>条</span></td>
  		<td>非微信号码:<span style="color:red"><?php echo ($resource["resCount"]["5"]); ?>条</span></td>
  		</tr>
  		<tr>
  		<td colspan="6">
  		<select name="" id="selectuserid" style="margin-top: 10;">
        <option selected="selected" value="-1">选择分配人员</option>
        <?php if(is_array($user)): $i = 0; $__LIST__ = $user;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$r): $mod = ($i % 2 );++$i;?><option value="<?php echo ($r["userid"]); ?>"><?php echo ($r["username"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
        </select>
  <select name="" id="statusid" style="margin-top: 10;">
    <option selected="selected" value="-1">请选择资源状态</option>
    <option value="0">未使用</option>
    <option value="1">申请未通过</option>
    <option value="2">已通过</option>
    <option value="3">意向客户</option>
    <option value="4">已入金</option>
    <option value="5">非微信号码</option>
 </select>
  	<input placeholder="请输入分配数量" id="count">&nbsp;&nbsp;<input value="分配" class="btn btn-primary" onclick="distribute()" type="button">
     
  </td>
 </tr>
  		
  	</tbody></table>
  	<table class="table table-bordered table-hover definewidth m10">
  			<tbody>
  				<tr align="center">
  				    <td>资源号码</td>
  				     <td width="100px">状态</td>
  				     <td width="440px">修改状态下拉列表</td>
  				     <td width="150px">资源备注</td>
  				     <td width="120px">更新时间</td>
  				     <td width="60px">操作</td>
  				    </tr>
  		     <?php if(is_array($resourceInfo)): $i = 0; $__LIST__ = $resourceInfo;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$r): $mod = ($i % 2 );++$i;?><tr>
  				<td><span id="pnumber126345"><?php echo ($r["pnumber"]); ?></span><!-- <input value="复制" class="btn btn-primary" onclick="copy2Clip(126345)" type="button"> -->
  				</td>
  				<td>
  				<?php if($r["sid"] == 0): ?>未使用<?php endif; ?>
  				 <?php if($r["sid"] == 1): ?>申请未通过<?php endif; ?>
  				 <?php if($r["sid"] == 2): ?>已通过<?php endif; ?>
  				 <?php if($r["sid"] == 4): ?>已入金<?php endif; ?>
  				 <?php if($r["sid"] == 5): ?>非微信号码<?php endif; ?>
  				 <?php if($r["sid"] == 6): ?>A类意向客户<?php endif; ?>
                 <?php if($r["sid"] == 7): ?>B类意向客户<?php endif; ?>
  				 <?php if($r["sid"] == 8): ?>C类意向客户<?php endif; ?>
  				 <?php if($r["sid"] == 9): ?>D类意向客户<?php endif; ?>
  				</td>
  				<td>
  				   <select id="<?php echo ($r["id"]); ?>" name="sid" style="float:left" onchange="test(<?php echo ($r["id"]); ?>)">
  					<option selected="selected" value="-1">请选择</option>
  					<option value="1">申请未通过</option>
  					<option value="2">已通过</option>
  					<option value="3">意向客户</option>
  					<option value="4">已入金</option>
  					<option value="5">非微信号码</option>
  				  </select>
  				<div id="childselect<?php echo ($r["id"]); ?>" style="display:none;float:left">
  					<select name="sid" id="myresourceid<?php echo ($r["id"]); ?>">
  						<option selected="selected" value="-1">请选择</option>
  						<option value="6">A类意向客户</option>
  						<option value="7">B类意向客户</option>
  						<option value="8">C类意向客户</option>
  						<option value="9">D类意向客户</option>
  					</select>
  				</div>
  		        </td>
  		          
  		        <td>
  		        <input id="wechatname<?php echo ($r["id"]); ?>" type="text" value="<?php echo ($r["wechatname"]); ?>">
  		        </td>

  		        <td>
  		        <?php echo (date('Y-m-d H:i',$r["updatetime"])); ?>
  		        </td>
  		        <td>
  		        <a href="javascript:update(<?php echo ($r["id"]); ?>)" style="text-decoration: NONE" class="btn btn-primary">提交</a>
  		        </td>
  		   </tr><?php endforeach; endif; else: echo "" ;endif; ?>
  	  </tbody></table>
  		<div class="inline  page" style="text-align: center;">
         <?php echo ($zcount); ?> 条记录 <?php echo ($page); ?>/<?php echo ($resPage); ?>页 
  　      <a style="margin-right: -10px;" href="javascript:upPage(<?php echo ($page); ?>)">上一页</a>
  　     <span style="color:red"><?php echo ($page); ?></span>
   　　   <a style="margin-left: -30px;" href="javascript:nextPage(<?php echo ($page); ?>,<?php echo ($resPage); ?>)">下一页</a>
         &nbsp;&nbsp;&nbsp;跳转到第<input id="toPage" style="width:30px;height:20px;padding-top: 4px;" type="text">页
          <a href="javascript:toGoPage()">跳转</a>
    　</div> 
  
       <a href="#" onclick="pupopen()"></a>
       <div id="bg"></div>
       <div id="popbox">
          <img src="/ncrm/Public/Admin/images/loading.gif">
          <a href="#"  onclick="pupclose()"></a>
      </div>

</body>
<script type="text/javascript" src="/ncrm/Public/Admin/js/jquery.js"></script>
    <script type="text/javascript" src="/ncrm/Public/Admin/js/bootstrap.js"></script>
    <script type="text/javascript" src="/ncrm/Public/Admin/js/ckform.js"></script>
    <script type="text/javascript" src="/ncrm/Public/Admin/js/common.js"></script>
    <script type="text/javascript">
     function pupopen(){
          document.getElementById("bg").style.display="block";
          document.getElementById("popbox").style.display="block" ; 
    }

    function pupclose(){
          document.getElementById("bg").style.display="none";
          document.getElementById("popbox").style.display="none" ;  
    }
</script>
	<script type="text/javascript">
		
	function distribute(){
		var userid = $("#selectuserid").val();
	
		if(userid==-1){
			alert("请选择将要分配的员工");
			return;
		}
		var statusid=$("#statusid").val();
		if(statusid==-1){
			alert("请选择将要分配的资源类型");
			return;
		}
		var count = $("#count").val();
		if(count==""||isNaN(count)){
			alert("请输入正确的分配数量");
			return;
		}
		if(count<=0){
			return;
		}
		var cou = parseInt(count);
		if(statusid==0){
			var unUser = $("#static0").val();
			var unUser = parseInt(unUser);
			if(cou>unUser){
				alert("输入的数量大于可用资源数量");
				return;
			}
		}
		if(statusid==1){
			var unGo = $("#static1").val();
			var unGo1 = parseInt(unGo);
			if(cou>unGo1){
				alert("输入的数量大于可用资源数量");
				return;
			}
		}	
		if(statusid==2){
			var readyGo = $("#static2").val();
			var readyGo = parseInt(readyGo);
			if(cou>readyGo){
				alert("输入的数量大于可用资源数量");
				return;
			}
		}
		if(statusid==3){
			var interested = $("#static3").val();
			var interested = parseInt(interested);
			if(cou>interested){
				alert("输入的数量大于可用资源数量");
				return;
			}
		}	
		if(statusid==4){
			var golden = $("#static4").val();
			var golden = parseInt(golden);
			if(cou>golden){
				alert("输入的数量大于可用资源数量");
				return;
			}
		}
		if(statusid==5){
			var golden = $("#static5").val();
			var golden = parseInt(golden);
			if(cou>golden){
				alert("输入的数量大于可用资源数量");
				return;
			}
		}
		var run = confirm("是否分配资源?");
		if(run){
              pupopen();
              $.ajax({
              type: 'POST',
              url: "<?php echo U('Lizhi/allocate');?>",
              data: {"userid":userid,"statusId":statusid,"count":count},
              dataType : "json", 
              success: function(data) {
                pupclose();
                 if(data.ok==1){
                     alert("分配成功");
                     window.location.reload();
                  }
                  if(data.ok==2){
                     alert("分配失败");
                     window.location.reload();
                  }
                }
            }) 
		}		
	}
	
	function upPage(page){
		if(page==1){
			alert('已经是第一页了');
		}else{
			page--;
		}
		window.location.href="lzygzy?page="+page;
       
	}
	function nextPage(page,pa){

		if(page==pa){
			alert('已经是最后一页了');
		}else{
			page++;
		}
		window.location.href="lzygzy?page="+page;
       
	}
	function toGoPage(pa){
		var page = $('#toPage').val();
		if(page>pa){
			alert('页数为'+pa+'页，请核对输入页数！');
			return;
		}
		if(isNaN(page)){
			alert('请输入数字');
			exit;
		}
		window.location.href="lzygzy?page="+page;
	}


function update(obj){
			var resourceid = obj;	
			var statusid=$("#"+obj+"").val();
			if(statusid==3){
				statusid=$("#myresourceid"+obj+"").val();
			}
			var wechatname = $("#wechatname"+obj+"").val();
			if(statusid!=6){
				if(wechatname==""){
				alert("请输入资源备注");
				return ;
				}	
			}
			if(statusid==-1){
				alert("请选择资源状态");
				return ;
			}

			var run = confirm("是否更新资源?");
			if(run){
            $.ajax({
              type: 'POST',
              url: "<?php echo U('Lizhi/update');?>",
              data: {"resourceId":resourceid,"statusId":statusid,"wechatName":wechatname},
              dataType : "json", 
              success: function(data) {
                 if(data.ok==1){
                     alert("修改成功");
                     window.location.reload();
                     var statusid=$("#"+obj+"").val(-1);
                  }
                  if(data.ok==2){
                     alert("修改失败");
                     window.location.reload();
                     var statusid=$("#"+obj+"").val(-1);
                  }
              }
          }) 
			}
		}


		function test(obj){
		var statusid = $("#"+obj+"").val();
		if(statusid==3){
			$("#childselect"+obj+"").show();
				
		}else{
			$("#childselect"+obj+"").hide();
		}
	}
</script>
</html>